const car_license = {province:'鄂',type:'A',carID:''}
const one_apply_conpany = {apply_title:'',apply_cars:[{license:car_license,tel:''}]}
const today = new Date()
const overtime = 4
new Vue({
	el:'#meeting',
	data:{	
		meeting_title:'',
		title_list: [],
		//选择会议名
		selected_title:'',
		select_meeting_title:[],
		host_cars:[{province:'鄂',type:'A',carID:''}],
		//起始时间
		start_hour:'7',
		end_hour:'18',
		start_day:'',
		start_days:[],
		end_day:'',
		end_days:[],
		//参会单位
		applyList:[],
		//时间阈值
		overtime:1
	},
	mounted:function(){
		//获取天数
		this.$http.post("http://127.0.0.1:81/local.car.com/index.php/Admin/test/opo",{emulateJSON:true}).then(response=>{
			console.log(response.data)	
			this.overtime = response.data
			this.SetDay()
		});		
	},
	methods:{
		SelectTitle:function(){
			this.selected_title =  1
			this.select_meeting_title = [1,2,3]			
		},
		//添加主办车
		AddMeetingCar:function(){
			this.host_cars.push({province:'鄂',type:'A',carID:''})
		},
		//删除主办车
		RemoveMeetingCar:function(){
			this.host_cars.pop()
		},
		//设置起始日期
		SetDay:function(){
			this.start_day = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate()
			this.end_day = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate()			
			this.FillDays('start_days')
			this.FillDays('end_days')
		},
		//添加时间选项
		FillDays:function(data){
			this[data] = []
			var now = new Date()
			var days = []
			for(var i = 0; i < this.overtime; i++) {
				days.push(now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate())
				now.setDate(now.getDate() + 1)
			}	
			this[data] = days
		},
		ChangeEnd:function(event){
			this.end_days = []
			this.end_day = this.start_day
			var now = new Date(this.start_day)
			var days = []
			for(var i = 0; i < this.overtime; i++) {
				days.push(now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate())
				now.setDate(now.getDate() + 1)
			}	
			this.end_days = days			
		},
		//添加参会单位
		meeting_addConferenceInfo:function(){
			this.applyList.push({apply_title:'',apply_cars:[{license:{province:'鄂',type:'A',carID:''},tel:''}]})
		},
		//添加参会车辆
		AddApplyCar:function(item){
//			console.log(item.apply_cars)
			item.apply_cars.push({license:{province:'鄂',type:'A',carID:''},tel:''})
		},
		//删除参会单位
		RemoveApplyCar:function(item){
			item.apply_cars.pop()
		},
		//删除参会单位
		removeConferenceInfo:function(item,index){
			this.applyList.splice(index,1)
		},
		//检测车牌
		checkedValid:function(event){
			console.log(event.target)
			var carID = event.target.valueOf()
			var reg = /[0-9 A-Z a-z]{5}/
			if(carID.value.match(reg)==null){
       			carID.setCustomValidity("请输入车牌后五位");
       		}else{
       			carID.setCustomValidity("");
       		}
		},
		//收集数据，提交表单，利用表单验证
		submitApply:function(){
			var form = document.getElementById('meeting_apply')
			var carID = document.getElementsByClassName('carID')
			if(!form.checkValidity()){
				document.getElementById('submit').click()
			}else{
				var data={	
					meeting_title:this.meeting_title,
					host_cars:this.host_cars,
					//起始时间
					start_hour:this.start_hour,
					end_hour:this.end_hour,
					start_day:this.start_day,
					end_day:this.end_day,
					//参会单位
					applyList:this.applyList
				}
				console.log(data)
			}
		}
	}
})

